<template>
  <div class="code-container">
    <div class="content first">
      <ul>
        <li>
          <span>构件编号</span>
          <p>{{cp_num}}</p>
        </li>
        <li>
          <span>构件类型</span>
          <p>{{component_name}}</p>
        </li>
        <li>
          <span>项目名称</span>
          <p>{{project_name}}</p>
        </li>
        <li>
          <span>项目地址</span>
          <p>{{address}}</p>
        </li>
        <li>
          <span>施工单位</span>
          <p>杭州市装配式建筑管理平台</p>
        </li>
        <li>
          <span>项目经理</span>
          <p></p>
        </li>
      </ul>
    </div>
    <div class="content progress">
      <p class="title">构件进度</p>
      <div class="percent">
        <span>{{progress}}%</span>
        <p>完成度</p>
      </div>
      <ul class="square">
        <li class="blue"> </li>
        <li> </li>
        <li> </li>
        <li> </li>
        <li> </li>
        <li> </li>
      </ul>
      <ul class="detail">
        <li class="active"> 加工制作 </li>
        <li class="active"> 工厂堆放 </li>
        <li class="active"> 道路运输 </li>
        <li class="active"> 现场堆放 </li>
        <li class="active"> 现场安装 </li>
        <li class="active"> 安装完成 </li>
      </ul>
      <ul class="info">
        <li>
          <i></i>
          <span>检查结果</span>
          <p>{{result=='1'?'合格':'不合格'}}</p>
        </li>
        <li>
          <i></i>
          <span>当前状态</span>
          <p>加工制作-构件养护与脱模</p>
        </li>
        <li>
          <i></i>
          <span>检查时间</span>
          <p>2019-08-29</p>
        </li>
      </ul>
    </div>
    <div class="content floor">
      <p class="title">基本信息</p>
      <ul class="basic">
        <li><span>楼层</span>
          <p>{{build_no}}</p>
        </li>
        <li><span>层号</span>
          <p>{{floor_no}}</p>
        </li>
        <li><span>ID芯片</span>
          <p>-</p>
        </li>
      </ul>
      <p class="title">制作信息</p>
      <ul class="basic">
        <li><span>生产时间</span>
          <p>-</p>
        </li>
        <li><span>工厂堆放</span>
          <p>-</p>
        </li>
        <li><span>构件加工厂</span>
          <p>构件厂测试1</p>
        </li>
        <!-- <li><span>原材料厂家</span><p></p></li> -->
      </ul>
      <p class="title">运输信息</p>
      <ul class="basic">
        <li><span>出厂时间</span>
          <p>{{out_date}}</p>
        </li>
        <li><span>北斗定位</span>
          <p>{{gps_num}}</p>
        </li>
        <li><span>车牌号</span>
          <p>{{car_num}}</p>
        </li>
        <li><span>车辆类型</span>
          <p>-</p>
        </li>
        <li><span>司机姓名</span>
          <p>{{leader}}</p>
        </li>
        <li v-show="pointList.length!=0?true:false"><span>构件轨迹</span>
          <p id="container"
             style="width:100%;height: 300px;margin-top:40px"> </p>
        </li>
      </ul>
      <p class="title">安装信息</p>
      <ul class="basic fix">
        <li><span>进场时间</span>
          <p>{{scene_date}}</p>
        </li>
        <li><span>现场堆场</span>
          <p>-</p>
        </li>
        <li><span>质量负责人</span>
          <p></p>
        </li>
        <!-- <li><span>吊装负责人</span><p></p></li> -->
        <li><span>完成时间</span>
          <p>{{end_install_date}}</p>
        </li>
      </ul>
    </div>
  </div>
</template>
<script>
import { componListApi } from '@/services/ProjectCenter'
import { standardCodeApi } from '@/services/StandardCode'
export default {
  data () {
    return {
      pointList: [],
      cp_num: "",
      project_name: "",
      address: "",
      progress: "",
      build_no: "",
      floor_no: "",
      result: "",
      car_num: "",
      out_date: "",
      leader: "",
      gps_num: "",
      scene_date: "",
      end_install_date: "",
      component_name: ""
    }
  },
  methods: {
    //创建地图
    createMap () {
      var map = new BMap.Map("container");
      var point = new BMap.Point(120.162341, 30.27743);
      map.centerAndZoom(point, 10);
      map.enableScrollWheelZoom(); // 开启鼠标滚轮缩放
      map.addControl(new BMap.NavigationControl({ anchor: BMAP_ANCHOR_BOTTOM_RIGHT }));
      map.addControl(new BMap.ScaleControl());
      if (typeof (this.pointList) != "undefined" && this.pointList.length != 0 && JSON.stringify(this.pointList) != "{}") {
        var start = new BMap.Marker(new BMap.Point(this.pointList[0].lon, this.pointList[0].lat), {
          icon: new BMap.Icon("https://webapi.amap.com/theme/v1.3/markers/n/start.png", new BMap.Size(30, 82), { imageOffset: new BMap.Size(7, 12) })
        });
        var end = new BMap.Marker(new BMap.Point(this.pointList[this.pointList.length - 1].lon, this.pointList[this.pointList.length - 1].lat), {
          icon: new BMap.Icon("https://webapi.amap.com/theme/v1.3/markers/n/end.png", new BMap.Size(42, 85), { imageOffset: new BMap.Size(10, 11) })
        });
        map.centerAndZoom(new BMap.Point(this.pointList[0].lon, this.pointList[0].lat), 13);
        map.addOverlay(start)
        map.addOverlay(end)
        for (var i = 0; i < this.pointList.length - 2; i++) {
          var polyline = new BMap.Polyline([
            new BMap.Point(this.pointList[i].lon, this.pointList[i].lat),//起始点的经纬度
            new BMap.Point(this.pointList[i + 1].lon, this.pointList[i + 1].lat)//终点的经纬度
          ], {
              strokeColor: "#0091ff",//设置颜色
              strokeWeight: 2, //宽度
              strokeOpacity: 0.9
            });//透明度
          map.addOverlay(polyline);
        }
      }
    },
    getData () {
      componListApi.getCodeInfo({
        params: {
          id: this.$route.query.id
        }
      }).then(res => {
        console.log('info', res)
        this.cp_num = res.data.cp_num
        this.project_name = res.data.project.project_name
        this.address = res.data.project.address
        this.progress = res.data.progress
        this.build_no = res.data.build_no
        this.floor_no = res.data.floor_no
        this.result = res.data.component_report.result
        this.car_num = res.data.car.car_num
        this.out_date = res.data.out_date
        this.leader = res.data.car.leader
        this.scene_date = res.data.scene_date
        this.gps_num = res.data.gps.gps_num
        this.end_install_date = res.data.end_install_date
        this.pointList = res.data.component_car_number
        for (var j = 0; j < this.memberType.length; j++) {
          if (res.data.cp_type === this.memberType[j].value) {
            res.data.component_name = this.memberType[j].name
          }
        }
        this.component_name = res.data.component_name
        // this.pointList = [
        //   {
        //     lon: '120.13414284140691',
        //     lat: '30.520196838324566'
        //   },
        //   {
        //     lon: '120.1341428415674',
        //     lat: '30.52019883895704'
        //   },
        //   {
        //     lon: '120.13414284172784',
        //     lat: '30.5202008395895'
        //   },
        //   {
        //     lon: '120.13407097026213',
        //     lat: '30.520112914029447'
        //   }
        //   ,
        //   {
        //     lon: '120.13347207474135',
        //     lat: '30.519893689031594'
        //   },
        //   {
        //     lon: '120.13256970379487',
        //     lat: '30.519458797728046'
        //   }, {
        //     lon: '120.13258567108423',
        //     lat: '30.519414762060453'
        //   },
        //   {
        //     lon: '120.13227423683477',
        //     lat: '30.519399180031076'
        //   },
        //   {
        //     lon: '120.13205063334736',
        //     lat: '30.519297449227764'
        //   }, {
        //     lon: '120.13196278616414',
        //     lat: '30.5192275450136'
        //   }
        // ]
        this.createMap();
      })
    },
    //获取构件类型
    getMemberType () {
      standardCodeApi.getStandardCodeData({
        data: {
          code_type: 'component_type'
        }
      }).then(res => {
        this.memberType = res.data.list
      })
    },
    //获取构件状态
    getMemberStatus () {
      standardCodeApi.getStandardCodeData({
        data: {
          code_type: 'component_sort'
        }
      }).then(res => {
        console.log('status', res)
      })
    },
  },
  created () {
    this.getData()
    this.getMemberType()
    this.getMemberStatus()
  },
  mounted () {
    this.createMap()
  }
}
</script>

<style lang="scss" scoped>
.code-container {
  background: #eee;
}
.content {
  margin: 0 0.15rem;
  background: #fff;
  font-size: 0.25rem;
  padding: 0.3rem;
  color: #333;
}
.first {
  border-top: 3px solid #123eab;
  line-height: 0.4rem;
  ul {
    padding: 0.2rem 0;
    li {
      list-style: none;
      span {
        color: #666;
        margin-right: 0.2rem;
        display: inline-block;
        width: 1.4rem;
        float: left;
      }
      p {
        display: inline-block;
        width: 4rem;
      }
    }
  }
}
.progress {
  margin: 0.2rem 0.15rem;
  .title {
    color: #123eab;
    font-size: 0.33rem;
    padding: 0.1rem 0;
  }
  .percent {
    text-align: center;
    margin-bottom: 0.3rem;
    span {
      font-size: 0.7rem;
      color: #000;
      margin-right: 0.2rem;
      font-weight: 800;
    }
    p {
      display: inline-block;
      font-size: 0.3rem;
    }
  }
  .square {
    width: 6.5rem;
    margin: 0 auto;
    overflow: hidden;
    li {
      width: 0.9rem;
      height: 0.3rem;
      background: #d4e2fe;
      float: left;
      margin: 0.05rem;
    }
    .blue {
      background: #1f64f0;
    }
  }
  .detail {
    padding: 0.2rem 0;
    width: 6.5rem;
    margin: 0 auto;
    overflow: hidden;
    li {
      float: left;
      color: #999;
      font-size: 0.18rem;
      width: 0.9rem;
      margin: 0 0.05rem;
      text-align: center;
    }
    .active {
      color: #333;
    }
  }
  .info {
    li {
      line-height: 0.4rem;
      list-style: none;
      i {
        display: inline-block;
        width: 0.1rem;
        height: 0.1rem;
        border-radius: 50%;
        background: red;
        float: left;
        margin-top: 0.15rem;
        margin-right: 0.1rem;
      }
      span {
        color: #666;
        margin-right: 0.2rem;
        display: inline-block;
        width: 1.4rem;
        float: left;
      }
      p {
        display: inline-block;
        width: 4rem;
      }
    }
  }
  .info > :nth-child(1) i {
    background: #00d94c;
  }
  .info > :nth-child(2) i {
    background: #0064ed;
  }
  .info > :nth-child(3) i {
    background: #ff6c00;
  }
}
.floor {
  .title {
    color: #123eab;
    font-size: 0.33rem;
    padding: 0.1rem 0;
  }
  .basic {
    padding-bottom: 0.15rem;
    border-bottom: 1px dashed #ccc;
    li {
      line-height: 0.4rem;
      list-style: none;
      span {
        color: #666;
        margin-right: 0.2rem;
        display: inline-block;
        width: 1.4rem;
        float: left;
      }
      p {
        display: inline-block;
        width: 4rem;
      }
    }
  }
}
</style>
